// <copyright file="LanguageAutoCompleteHandler.cs" company="YUIAsp.Net">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>raul popescu</author>
// <email>dev@yuiasp.net</email>
// <date>2009-01-30</date>
// <summary>YUIAsp.Net File</summary>

using System.Globalization;
using YUIAspNet;

namespace YUIAspNetDemo.AutoComplete
{
    /// <summary>
    /// Used by the AutoComplete control to get a list of languages
    /// </summary>
    public class LanguageAutoCompleteHandler : BaseAutoCompleteHandler
    {
        /// <summary>
        /// Gets the results.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="maxItems">The max items.</param>
        /// <param name="autoCompleteCode">The auto complete code.</param>
        /// <returns> a</returns>
        public override LocalDataSource GetResults(string query, int maxItems, string autoCompleteCode)
        {
            LocalDataSource src = new LocalDataSource();

            src.AddColumn("lang");
            src.AddColumn("langNative");

            foreach (CultureInfo culture in CultureInfo.GetCultures(CultureTypes.AllCultures))
            {
                if (culture.EnglishName.ToLower().StartsWith(query.ToLower()))
                {
                    src.AddRow(culture.EnglishName, culture.NativeName);
                    if (src.Count >= maxItems) break;
                }
            }

            return src;
        }
    }
}
